import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-04-08
 * Time: 21:26
 */
public class demo4 {
    private volatile static int flag = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while(flag == 0){

            }
            System.out.println("t1 线程结束");
        });

        Thread t2 = new Thread(() -> {
            //针对 flag 进行修改
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入 flag 的值：");
            flag = scanner.nextInt();
        });

        t1.start();
        t2.start();
    }
}
